<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>告警处理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include>
	<style type="text/css">
	    #authority table, caption, tbody, tfoot, thead, tr, th, td{
	        vertical-align: middle;
	    }
	</style>
	<script type="text/javascript">
	$(document).ready(function() {
		var h = '85%';
 		if($.browser.msie && ($.browser.version == 8.0 || $.browser.version == 9.0)){
 	    	 h = $(self.parent.parent.frames['mainFrame']).height()-87; 
 	    }
        $("#alarmHandle").omGrid({
        	dataSource : 'alarmHandle!findAll.do',
            height : h,
            limit : 20,
            showIndex : true,
            colModel : [ 
                         {header : '名称', name : 'name', width : 150, align : 'left'},
                         {header : '通知方式', name : 'type', width : 70, align : 'center',renderer:function(value){
                             if(value == '1') {
                            	 return '短信';
                             }else if(value == '2') {
                            	 return '邮件';
                             }else{
                            	 return '短信/邮件';
                             }
                         }},
                         {header : '告警分类', name : 'alarmClassName', width : 150, align : 'left'},
                         {header : '接收角色', name : 'acceptorName', width : 180, align : 'left'},
                         {header : '间隔时间(秒)', name : 'intervalValue', width : 70, align : 'left'}, 
                         {header : '接受频率', name : 'recvValue', width : 70, align : 'center'} ]
        });
        
        $("#alarmHandleEditor").omDialog({
        	autoOpen: false,
  		    height: 300,
  		    width : 480,
  		    buttons: [{
                text : "确定", 
                click : function () {
                  $("#alarmHandleForm").submit();
                }
             }, {
                text : "取消", 
                click : function () {
                  $("#alarmHandleEditor" ).omDialog("close");
              }
          }]
        });
        
        
        $("#alarmHandleAdd").click(function(){
        	$("#alarmHandleForm").resetForm();
        	$("#alarmHandleId").val('');
        	$("#alarmHandleAcceptor").val('');
        	$("#alarmHandleClassId").val('');
        	$("#alarmHandleEditor").omDialog("open");
        });
        
        $("#alarmHandleDelete").click(function(){
        	var selects = $("#alarmHandle").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择删除记录'});
        		return;
        	}
        	 $.omMessageBox.confirm({
                 title:'确认删除',
                 content:'您确定删除该数据？',
                 onClose:function(result){
                	 if(result){
                		 $.ajax({
                			 url : 'alarmHandle!delete.do',
                			 data : {deleteId:selects[0].id},
                			 success : function(data){
                				 if(data == '1'){
                					 $.omMessageTip.show({timeout : 2000,content : '删除成功！'});
                					 $("#alarmHandle").omGrid("reload");
                				 }else{
                					 $.omMessageTip.show({timeout : 2000,content : '删除失败！'});
                				 }
                			 }
                		 });
                	 }
                 }
             });

        	
        });
        
        $("#alarmHandleModify").click(function(){
        	var selects = $("#alarmHandle").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择修改记录'});
        		return;
        	}
        	$.ajax({
  			  url: "alarmHandle!findByID.do",
  			  data : {alarmHandleId : selects[0].id},
  			  dataType : 'json',
  			  success: function(data){
  	        	$("#alarmHandleForm").resetForm();
  	        	$("#alarmHandleId").val(data[0].id);
  	        	$("#alarmHandleName").val(data[0].name);
  	        	$("#alarmHandleType").val(data[0].type);
  	        	$("#alarmHandleClassName").val(data[0].alarmClassName);
  	        	$("#alarmHandleClassId").val(data[0].alarmClassId);
  	        	$("#acceptorName").val(data[0].acceptorName);
  	        	$("#alarmHandleAcceptor").val(data[0].acceptor);
  	        	$("#intervalValue").val(data[0].intervalValue);
  	        	$("#recvValue").val(data[0].recvValue);
  			  }
  			});
        	$("#alarmHandleEditor").omDialog("open");
        });
        
        var alarmHandleOptions  = {
      		  url : 'alarmHandle!save.do',
                success : function(data){
                   	if(data != '0'){  
                       	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                       	$("#alarmHandleEditor").omDialog('close');
                       	$("#alarmHandle").omGrid("reload");
                   	}else{
                   		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
                   	}
                }
      	  };
      	  $("#alarmHandleForm").submit(function() {
                $(this).omAjaxSubmit(alarmHandleOptions);
                return false;//返回false,阻止浏览器默认行为
          });

        $('#acceptorName').bind('focus',function(){
        	if($('#roleTree').html() == ''){
	        	$('#roleTree').omTree({
	                dataSource : 'alarmHandle!findRoleList.do',
	                showCheckbox:true
	            });
        	}
        	if($("#alarmHandleAcceptor").val() == ''){
            	$("#roleTree").omTree("checkAll", false);
        	}else{
        		var ids = $("#alarmHandleAcceptor").val().split(",");
        		for(var i = 0;i<ids.length;i++){
                    $("#roleTree").omTree("check", $("#roleTree").omTree("findNode","id",ids[i]));
        		}
        	}
        	$('#roleSelect').omDialog("open");
        });
      	  
      	$("#roleSelect").omDialog({
        	autoOpen: false,
  		    height: 450,
  		    width : 280,
            modal : true,
  		    buttons: [{
	              text : "确定", 
	              click : function () {
	            	  var treeNodes = $("#roleTree").omTree("getChecked", true);
	            	  var checkedIds = "";
	            	  var checkedNames = "";
	            	  for(var i = 0;i < treeNodes.length;i++){
	            		  if(i == treeNodes.length - 1){
		            		  checkedIds += treeNodes[i].id;
		            		  checkedNames += treeNodes[i].text;
	            		  }else{
	            			  checkedIds += treeNodes[i].id + ",";
		            		  checkedNames += treeNodes[i].text + ",";
	            		  }
	            	  }
	            	  
	            	  $("#alarmHandleAcceptor").val(checkedIds);
	            	  $("#acceptorName").val(checkedNames);
	                  $("#roleSelect" ).omDialog("close");
	              }
	          }, {
	              text : "取消", 
	              click : function () {
	                  $("#roleSelect" ).omDialog("close");
	              }
	          }]

        });

        $('#alarmHandleClassName').click('focus',function(){
        	if($('#alarmClassTree').html() == ''){
	        	$('#alarmClassTree').omTree({
	                dataSource : 'alarmHandle!findAlarmClassList.do'
	            });
        	}
        	$('#alarmClassSelect').omDialog("open");
        });
      	
      	$("#alarmClassSelect").omDialog({
        	autoOpen: false,
  		    height: 450,
  		    width : 280,
            modal : true,
  		    buttons: [{
	              text : "确定", 
	              click : function () {
	            	  var treeNode = $("#alarmClassTree").omTree("getSelected");
	            	  $("#alarmHandleClassId").val(treeNode.id);
	            	  $("#alarmHandleClassName").val(treeNode.text);
	                  $("#alarmClassSelect" ).omDialog("close");
	              }
	          }, {
	              text : "取消", 
	              click : function () {
	                  $("#alarmClassSelect" ).omDialog("close");
	              }
	          }]

        });
    });
	</script>  
  </head>
  
  <body>
    <div class="toolbar mar">
		         <a href="#" class="rbutton" id="alarmHandleAdd"><span><img src="../images/add.gif" width="14" height="14" /><ins>添加</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="alarmHandleModify"><span><img src="../images/add.gif" width="14" height="14" /><ins>修改</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="alarmHandleDelete"><span><img src="../images/del.gif" width="14" height="14" /><ins>删除</ins></span></a>
	</div>
    <table id="alarmHandle"></table>
    
    <div id="alarmHandleEditor" title="编辑内容" style="display: none;">
     <form id="alarmHandleForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="10%" align="right">名称：</td>
               <td width="28%" colspan="3" align="left">
                 <input type="hidden" id="alarmHandleId" name="alarmHandle.id">
                 <input type="text" name="alarmHandle.name" id="alarmHandleName" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">通知方式：</td>
               <td width="28%" colspan="3" align="left">
                 <select name="alarmHandle.type" id="alarmHandleType">
                 	<option value="1">短信</option>
                 	<option value="2">邮件</option>
                 	<option value="9">全部</option>
                 </select>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">接收角色：</td>
               <td width="10%" colspan="3" align="left">
                  <input type="hidden" value="" id="alarmHandleAcceptor" name="alarmHandle.acceptor" class="input_text" />
                  <input type="text" id="acceptorName" name="alarmHandle.acceptorName" class="input_text" />
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">告警分类：</td>
               <td width="28%" colspan="3" align="left">
                  <input type="hidden" value="" id="alarmHandleClassId" name="alarmHandle.alarmClassId" class="input_text" />
                  <input type="text" id="alarmHandleClassName" name="alarmHandle.alarmClassName" class="input_text" />
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">间隔时间(秒)：</td>
               <td width="28%" colspan="3" align="left">
                  <input type="text" id="intervalValue" name="alarmHandle.intervalValue" class="input_text" />
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">接受频率：</td>
               <td width="28%" colspan="3" align="left">
                  <input type="text" id="recvValue" name="alarmHandle.recvValue" class="input_text" />
               </td>
             </tr>
           </table>
         </form>
   </div>
   <div id="roleSelect" title="选择角色" style="display: none;">
   		<ul id="roleTree"></ul>
   </div>
   <div id="alarmClassSelect" title="选择告警类别" style="display: none;">
   		<ul id="alarmClassTree"></ul>
   </div>
  </body>
</html>
